﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MedReg
{
    public partial class PositionType : IEquatable<PositionType>
    {
        public void ImportList(List<Classes.PositionType> ptList)
        {
            var mdb = new MedregDBDataContext();
            var ListPt = new List<PositionType>();
            foreach (var pt in ptList)
            {
                PositionType pt1 = new PositionType() { ID = pt.ID, Name = pt.Name };
                PositionType query;

                if (mdb.PositionType.LongCount() == 0)
                {
                    mdb.PositionType.InsertOnSubmit(pt1);
                }
                else
                {
                    try
                    {
                        query = mdb.PositionType.Single(l => l.ID == pt1.ID);
                        query.Name = pt1.Name;

                    }
                    catch (ArgumentNullException e)
                    {
                    }
                    catch (InvalidOperationException e)
                    {

                        if (!ListPt.Contains(pt1))
                        {
                            mdb.PositionType.InsertOnSubmit(pt1);
                            ListPt.Add(pt1);
                        }
                    }
                }
            }
            mdb.SubmitChanges();
        }
        public bool Equals(PositionType other)
        {
            var i = this.ID.Equals(other.ID);
            var j = this.Name.Equals(other.Name);
            if (i & j)
            {
                return true;
            }
            return false;
        }
    }
}
